<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../vue.js"></script>
    <style>
      .box {
        height: 100vh;
      }
      .bgc {
        background-color: #000;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div :class="class1">
        <button @click="changeLight" v-text="btnText"></button>
      </div>
    </div>
  </body>
  <script>
    const vm = new Vue({
      el: "#app",
      data: {
        flag: true,
        btnText: "点击关灯",
        class1: { box: true, bgc: false },
      },
      methods: {
        changeLight() {
          this.class1.bgc = !this.class1.bgc;
          this.class1.bgc === true
            ? (this.btnText = "点击开灯")
            : (this.btnText = "点击关灯");
        },
      },
    });
  </script>
</html>
